package com.flyu.myThread.DownloaderDemo;

import java.io.IOException;
import java.net.FileNameMap;
import java.net.URL;
import java.io.File;
import org.apache.commons.io.*;

public class MyDownloader extends Thread {
    private static String url;
    private static String name;

    public MyDownloader(String url, String name) {
        this.url = url;
        this.name = name;
    }

    @Override
    public void run() {
        WebDownloader webdownloader = new WebDownloader();
        webdownloader.downloader(url, name);
        System.out.println("下载了文件"+name);

    }

    public static void main(String[] args) {
        MyDownloader t1 = new MyDownloader("https://cn.bing.com/images/search?view=detailV2&ccid=WPV2kisF&id=C9EEE91498D4B19D3010C262CB5EF85A0F351D1F&thid=OIP.WPV2kisFkjBPr-hTR7TtmwAAAA&mediaurl=https%3a%2f%2fwww.keaidian.com%2fuploads%2fallimg%2f190504%2f04235508_47.png&exph=156&expw=118&q=%e5%9b%be%e7%89%87&simid=608005792653126589&FORM=IRPRST&ck=CD2075BF10E26BA4EBAA5B3D83BAC6BE&selectedIndex=25&qft=+filterui%3aimagesize-small&ajaxhist=0&ajaxserp=0", "1.jpg");
        MyDownloader t2 = new MyDownloader("https://cn.bing.com/images/search?view=detailV2&ccid=%2BWAboUFD&id=51CBFCCE12F78298606B573259585D24352EFB65&thid=OIP.-WAboUFD04c791q6eVeLQAAAAA&mediaurl=https%3A%2F%2Fgss0.baidu.com%2F94o3dSag_xI4khGko9WTAnF6hhy%2Fzhidao%2Fpic%2Fitem%2Fb58f8c5494eef01f1202415ee1fe9925bc317d12.jpg&exph=177&expw=172&q=%e5%9b%be%e7%89%87&simid=608052397334015678&form=IRPRST&ck=F9C673893ACEA186E4CD8B5210CFED36&selectedindex=26&qft=+filterui%3aimagesize-small&ajaxhist=0&ajaxserp=0&vt=0&sim=11", "2.jpg");
        MyDownloader t3 = new MyDownloader("https://cn.bing.com/images/search?view=detailV2&ccid=NMEICJKn&id=8DE18EA22899BFCED9551C0369CF56D2B28B9A00&thid=OIP.NMEICJKnAMSyAz4vGCwxvQAAAA&mediaurl=https%3A%2F%2Ftse1-mm.cn.bing.net%2Fth%2Fid%2FR-C.34c1080892a700c4b2033e2f182c31bd%3Frik%3DAJqLstJWz2kDHA%26riu%3Dhttp%253a%252f%252fwww.jiongyaya.com%252fuploads%252fallimg%252f111117%252f1-11111GIH0.jpg%26ehk%3Dl0M9S2NWgiTEtj08vOX3uumHaf18crYBSjlyzUvcJPo%253d%26risl%3D%26pid%3DImgRaw%26r%3D0&exph=196&expw=193&q=%e5%9b%be%e7%89%87&simid=608055803249757364&form=IRPRST&ck=86F85B2CD1C4B0689E2B4B13F41162CC&selectedindex=27&qft=+filterui%3aimagesize-small&ajaxhist=0&ajaxserp=0&vt=0&sim=11", "3.jpg");

        t1.run();
    }
}

class WebDownloader{
    public void downloader(String url, String name) {
        try {
            FileUtils.copyURLToFile(new URL(url), new File(name));
        }catch (IOException e){
            e.printStackTrace();
            System.out.println("IO异常，downloader方法出现问题");
        }
    }
}
